#include "enemyplane.h"
#include"config.h"
#include<ctime>
#include<QRandomGenerator>
#include<QDebug>
EnemyPlane::EnemyPlane()
{

    int a= QRandomGenerator::global()->bounded(5);
    switch (a)
    {
    case 2:
        m_enemy.load(ENEMYPATH);
        m_shields=3;
        break;
    case 4:
    case 5:
         m_enemy.load(ENEMYPATH3);
         m_shields=2;
         break;
    default:
        m_enemy.load(ENEMYPATH1);
        m_shields=1;
        break;
    }
    //敌机位置
    m_X = 0;
    m_Y = 0;
    //敌机状态
    m_Free = true;
    //敌机速度
    m_Speed = ENEMY_SPEED;
    //敌机矩形
    m_Rect.setWidth(m_enemy.width());
    m_Rect.setHeight(m_enemy.height());
    m_Rect.moveTo(m_X,m_Y);
}
void EnemyPlane::updatePosition()
{
    //空闲状态，不计算坐标
    if(m_Free) { return; }
    m_Y += m_Speed;
    m_Rect.moveTo(m_X,m_Y);
}
void EnemyPlane::reload()
{
    int a= QRandomGenerator::global()->bounded(5);
    switch (a)
    {
    case 2:
        m_enemy.load(ENEMYPATH);
        m_shields=3;
        break;
    case 4:
    case 5:
         m_enemy.load(ENEMYPATH3);
         m_shields=2;
         break;
    default:
        m_enemy.load(ENEMYPATH1);
        m_shields=1;
        break;
    }
}
